package practice;

import java.util.ArrayList;
import java.util.List;

class TreeNode
{
    int val ;
    static  int i=1;
    TreeNode left;
    TreeNode right;
    TreeNode(int n)
    {
        this.val = n;
    }
    TreeNode()
    {

    }
    public static TreeNode createTree(List<Integer> list)
    {    //1.思路传入list ,位置i,

        TreeNode root=new TreeNode(list.get(0));

        crete(list,i,root);

        return root;
    }

    private static TreeNode crete(List<Integer> list, int i,TreeNode root) {

//           root = new TreeNode(list.get(i));
           if(i<=list.size()/2) {
               root.left = new TreeNode(list.get(i));
               crete(list,i+1,root.left);
           }
           if(i<list.size()&&i>list.size()/2) {
               root.right = new TreeNode(list.get(i));
               root.right = crete(list, i+1, root.right);
           }

       return root;
    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        createTree(list);
    }
}
 class Tree {
}
